#include "game.h"
#include "herocard.h"

Game::Game()
{
}

void Game::shuffle()
{
    if(leftGameCard.size() == 0 && throwedGameCard.size() == 0)
    {
        for(int i = 0; i < allGameCard.size(); i++)
        {
            throwedGameCard.append(allGameCard.at(i));
        }
    }

    srand(unsigned(time(0)));
    while(throwedGameCard.size() > 0)
    {
        int i = throwedGameCard.size() * rand() / (RAND_MAX + 1.0);
        leftGameCard.append(throwedGameCard.at(i));
        throwedGameCard.removeAt(i);
    }
}

QList<GameCard*> Game::getCard(int num)
{
    if(leftGameCard.size() < num)
        shuffle();

    QList<GameCard*> result;
    for(int i = 0; i < num && leftGameCard.size() > 0; i++)
    {
        result.append(leftGameCard.at(0));
        leftGameCard.removeFirst();
    }

    return result;
}

